<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "t_order".
 *
 * @property int $id ID
 * @property string $orderSn 订单编号
 * @property int $signUpId 报名ID
 * @property string $subject 标题
 * @property float $price 金额
 * @property float $payPrice 实际支付金额
 * @property int $status 订单状态(0:未完成, 1:完成,2:取消)
 * @property int $payStatus 支付状态(0:未支付,1:支付完成,2:超时未支付,3:退款完成)
 * @property int $payTime 支付时间
 * @property int $cancelTime 取消时间
 * @property int $_intm 创建时间
 * @property int $_uptm 更新时间
 */
class TOrder extends \yii\db\ActiveRecord
{
    const STATUS_INIT = 0;
    const STATUS_FINISH = 1;
    const STATUS_CANCEL = 2;

    const PAY_STATUS_INIT = 0;
    const PAY_STATUS_PAYED = 1;
    const PAY_STATUS_TIMEOUT = 2;
    const PAY_STATUS_REFUND = 3;

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 't_order';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['orderSn'], 'required'],
            [['signUpId', 'status', 'payStatus', 'payTime', 'cancelTime', '_intm', '_uptm'], 'integer'],
            [['price', 'payPrice'], 'number'],
            [['orderSn', 'subject'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'orderSn' => '订单编号',
            'signUpId' => '报名ID',
            'subject' => '标题',
            'price' => '金额',
            'payPrice' => '实际支付金额',
            'status' => '订单状态',
            'payStatus' => '支付状态',
            'payTime' => '支付时间',
            'cancelTime' => '取消时间',
            '_intm' => '创建时间',
            '_uptm' => '更新时间',
        ];
    }

    public function getSignup(){
        return $this->hasOne(TSignUp::class, ['id' => 'signUpId']);
    }
}
